<template>
  <div class="course">
    <van-dropdown-menu>
      <van-dropdown-item title="分类" ref="item">
        <p>{{ nianji.name }}</p>
        <div class="nianjilist">
          <p
            v-for="item in nianji.child"
            :key="item.id"
            @click="setnianji(item.id)"
          >
            {{ item.name }}
          </p>
        </div>
        <p>{{ xueke.name }}</p>
        <div class="nianjilist">
          <p
            v-for="item in xueke.child"
            :key="item.id"
            @click="setxueke(item.id)"
          >
            {{ item.name }}
          </p>
        </div>
        <div class="anniu">
          <van-button @click="chongzhi">重置</van-button>
          <van-button type="primary" @click="onchange">提交</van-button>
        </div>
      </van-dropdown-item>

      <van-dropdown-item v-model="value" :options="sort" @change="px" />

      <van-dropdown-item title="筛选">
        <van-cell center title="排序"> </van-cell>
        <van-cell center title="团购"></van-cell>
      </van-dropdown-item>
    </van-dropdown-menu>

    <div v-for="item in list" :key="item.id" class="home-courselist">
      <p class="courselist-1">{{ item.title }}</p>
      <div class="courselist-2">
        <p>共{{ item.total_periods }}课时</p>
      </div>
      <div class="courselist-3">
        <p class="pp">
          <img :src="item.teachers_list[0].teacher_avatar" /><span
            style="margin-left: 2.26667vw"
            >{{ item.teachers_list[0].teacher_name }}</span
          >
        </p>
      </div>
      <p class="courselist-4">
        <span style="color: rgba(0, 0, 0, 0.45)"
          >{{ item.sales_num }}人已报名</span
        >
        <span>{{ item.price == 0 ? "免费" : item.price * 0.01 + ".00" }}</span>
      </p>
    </div>

    <div class="btm"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      value: 0,
      switch1: false,
      switch2: false,
      sort: [
        { text: "综合排序", value: 0 },
        { text: "最新", value: 1 },
        { text: "价格从低到高", value: 2 },
        { text: "价格从高到低", value: 3 },
      ],
      copylist: [],
      list: [],
      nianji: [],
      xueke: [],
      nj: 0,
      xk: 0,
    };
  },
  mounted() {
    this.getcourseBasis();
    this.getcourseClassify();
  },
  methods: {
    getcourseBasis() {
      let params = {
        page: 1,
        limit: 10,
      };
      this.$API.courseBasis(params).then((res) => {
        this.list = res.data.data.list;
        this.copylist = res.data.data.list;
      });
    },
    getcourseClassify() {
      this.$API.courseClassify().then((res) => {
        // console.log(res);
        this.nianji = res.data.data.attrclassify[0];
        this.xueke = res.data.data.attrclassify[1];
      });
    },
    setnianji(e, index) {
      console.log(e);
      this.nj = e;
      if (e - 1 === index) {
        this.show = true;
      }
    },
    setxueke(e) {
      console.log(e);
      this.xk = e;
    },
    onchange() {
      this.$axios
        .get(
          `https://www.365msmk.com/api/app/courseBasis?page=1&limit=10&course_type=3&classify_id=&order_by=4&attr_val_id=${this.nj},${this.xk}&is_vip=0&`
        )
        .then((res) => {
          this.list = res.data.data.list;
        });
      this.$refs.item.toggle();
    },
    chongzhi() {
      this.list = this.copylist;
      this.$refs.item.toggle();
    },
    px(e) {
      console.log(e);
      this.$axios
        .get(
          `https://www.365msmk.com/api/app/courseBasis?page=1&limit=10&course_type=3&classify_id=&order_by=${e}&attr_val_id=&is_vip=0&`
        )
        .then((res) => {
          this.list = res.data.data.list;
        });
    },
  },
};
</script>

<style lang="scss">
.course {
  background-color: #f0f2f5;
}
.home-courselist {
  background: #fff;
  border-radius: 0.13333rem;
  border-radius: 1.33333vw;
  padding: 0 0.37333rem;
  padding: 0 3.73333vw;
  margin-bottom: 0.4rem;
  margin-bottom: 4vw;
  position: relative;
  .courselist-1 {
    padding-top: 4vw;
  }
  .courselist-2 {
    display: flex;
    align-items: center;
  }

  .courselist-3 {
    display: flex;
    height: 100%;
    align-items: center;
    .pp {
      display: flex;
      height: 100%;
      align-items: center;
      font-size: 3.2vw;
      color: rgba(0, 0, 0, 0.45);
      img {
        width: 7.2vw;
        height: 7.2vw;
        border-radius: 50%;
      }
    }
  }

  .courselist-4 {
    border-top: 1px solid #f5f5f5;
    height: 11.73333vw;
    line-height: 11.73333vw;
    display: flex;
    font-size: 3.46667vw;
    justify-content: space-between;
  }
}
.nianjilist {
  width: 94vw;
  margin: 0 4vw 0 4vw;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  p {
    margin: 10px 20px;
    background-color: rgba(0, 0, 0, 0.45);
    padding: 15px;
    color: white;
  }
  p:hover {
    color: orange;
  }
}
.btm {
  height: 10vh;
}
</style>